package rulebase;

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import lexicon.Lexicon;
import javax.swing.SwingConstants;
import java.awt.Font;


public class SimpleSpelloutRulePanel extends JPanel
{
	private JList SimpleFeaturesList;
	private JComboBox cbxSimpleModification;
	private JComboBox cbxSimpleTriggerWord;
	private JComboBox cbxSimpleBaseForm;
	private JTextField txtSimplePrefix;
	private JTextField txtSimpleSuffix;
	private JTextField txtSimpleInfix;
	private JTextField txtSimpleNewWord;
	private JTextField txtSimpleTranslation;
	private JTextField txtSimpleGloss;
	private JButton btnSimpleTriggerWord;
	private JCheckBox chkSimpleReduplication;
	
	private ArrayList<Lexicon> lexiconList = new ArrayList<>();
	
	public SimpleSpelloutRulePanel()
	{
		setLayout(null);
		initGUI();
	}
	
	private void initGUI()
	{
		
		JLabel lblSimpleModification = new JLabel("Modification");
		lblSimpleModification.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleModification.setBounds(14, 79, 86, 14);
		add(lblSimpleModification);
		
		JLabel lblSimpleBaseForm = new JLabel("Base Form");
		lblSimpleBaseForm.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleBaseForm.setBounds(14, 45, 86, 14);
		add(lblSimpleBaseForm);
		
		JLabel lblSimpleSuffix = new JLabel("Suffix");
		lblSimpleSuffix.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleSuffix.setBounds(35, 158, 65, 14);
		add(lblSimpleSuffix);
		
		JLabel lblSimplePrefix = new JLabel("Prefix");
		lblSimplePrefix.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimplePrefix.setBounds(35, 127, 65, 14);
		add(lblSimplePrefix);
		
		JLabel lblSimpleInfix = new JLabel("Infix");
		lblSimpleInfix.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleInfix.setBounds(41, 189, 59, 14);
		add(lblSimpleInfix);
		
		JLabel lblSimpleTranslation = new JLabel("Translation");
		lblSimpleTranslation.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleTranslation.setBounds(10, 251, 90, 14);
		add(lblSimpleTranslation);
		
		JLabel lblSimpleNewWord = new JLabel("New Word");
		lblSimpleNewWord.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleNewWord.setBounds(13, 220, 87, 14);
		add(lblSimpleNewWord);
		
		JLabel lblSimpleGloss = new JLabel("Gloss");
		lblSimpleGloss.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleGloss.setBounds(251, 189, 59, 14);
		add(lblSimpleGloss);
		
		JLabel lblSimpleFeatures = new JLabel("Features");
		lblSimpleFeatures.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSimpleFeatures.setBounds(17, 280, 83, 14);
		add(lblSimpleFeatures);
		
		cbxSimpleModification = new JComboBox();
		cbxSimpleModification.setBounds(110, 75, 150, 20);
		add(cbxSimpleModification);
		initCbxSimpleModificationItems();
		
		cbxSimpleTriggerWord = new JComboBox();
		cbxSimpleTriggerWord.setBounds(110, 11, 300, 20);
		add(cbxSimpleTriggerWord);
		
		cbxSimpleBaseForm = new JComboBox();
		cbxSimpleBaseForm.setBounds(110, 42, 150, 20);
		add(cbxSimpleBaseForm);
		
		btnSimpleTriggerWord = new JButton("T W");
		btnSimpleTriggerWord.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnSimpleTriggerWord.setBounds(14, 11, 86, 23);
		add(btnSimpleTriggerWord);

		txtSimplePrefix = new JTextField();
		txtSimplePrefix.setBounds(110, 127, 86, 20);
		add(txtSimplePrefix);
		txtSimplePrefix.setColumns(10);
		
		txtSimpleSuffix = new JTextField();
		txtSimpleSuffix.setColumns(10);
		txtSimpleSuffix.setBounds(110, 158, 86, 20);
		add(txtSimpleSuffix);

		txtSimpleInfix = new JTextField();
		txtSimpleInfix.setColumns(10);
		txtSimpleInfix.setBounds(110, 189, 86, 20);
		add(txtSimpleInfix);

		txtSimpleNewWord = new JTextField();
		txtSimpleNewWord.setColumns(10);
		txtSimpleNewWord.setBounds(110, 220, 86, 20);
		add(txtSimpleNewWord);

		txtSimpleTranslation = new JTextField();
		txtSimpleTranslation.setColumns(10);
		txtSimpleTranslation.setBounds(110, 251, 86, 20);
		add(txtSimpleTranslation);

		txtSimpleGloss = new JTextField();
		txtSimpleGloss.setColumns(10);
		txtSimpleGloss.setBounds(316, 186, 86, 20);
		add(txtSimpleGloss);
		
		chkSimpleReduplication = new JCheckBox("Reduplication");
		chkSimpleReduplication.setBounds(278, 123, 89, 23);
		add(chkSimpleReduplication);
		
		JScrollPane spSimpleFeatures = new JScrollPane();
		spSimpleFeatures.setBounds(110, 280, 300, 123);
		add(spSimpleFeatures);
		SimpleFeaturesList = new JList();
		spSimpleFeatures.setViewportView(SimpleFeaturesList);
	}
	
	private void initCbxSimpleModificationItems()
	{
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		model.addElement("Prefix");
		model.addElement("Suffix");
		model.addElement("Infix");
		model.addElement("Circumfix");
		model.addElement("Add Word");
		model.addElement("New Translation");
		cbxSimpleModification.setModel(model);
	}
	
	public void setSimpleFeaturesListModel(DefaultListModel model){
		SimpleFeaturesList.setModel(model);
	}
	
	public void addTriggerWord(Lexicon lex){
		lexiconList.add(lex);
		initCbxSimpleTriggerWord();
	}
	
	public void initCbxSimpleTriggerWord(){
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		
		for(int i=0; i<lexiconList.size(); i++)
			model.addElement(lexiconList.get(i).getName() + " - " + lexiconList.get(i).getGloss());
		
		cbxSimpleTriggerWord.setModel(model);
	}
	
	public void setCbxSimpleModificationListener(ActionListener AL)
	{
		cbxSimpleModification.addActionListener(AL);
	}
	
	public void setCbxSimpleTriggerWordListener(ActionListener AL)
	{
		cbxSimpleTriggerWord.addActionListener(AL);
	}
	
	public void setCbxSimpleBaseFormListener(ActionListener AL)
	{
		cbxSimpleBaseForm.addActionListener(AL);
	}
	
	public void setBtnSimpleTriggerWordListener(ActionListener AL)
	{
		btnSimpleTriggerWord.addActionListener(AL);
	}
	
	public void setChkSimpleReduplicationListener(ItemListener AL)
	{
		chkSimpleReduplication.addItemListener(AL);
	}
	
	public void setSimplePrefixText(String s)
	{
		txtSimplePrefix.setText(s);
	}
	
	public void setSimpleSuffixText(String s)
	{
		txtSimpleSuffix.setText(s);
	}
	
	public void setSimpleInfixText(String s)
	{
		txtSimpleInfix.setText(s);
	}
	
	public void setSimpleNewWordText(String s)
	{
		txtSimpleNewWord.setText(s);
	}
	
	public void setSimpleTranslationText(String s)
	{
		txtSimpleTranslation.setText(s);
	}
	
	public void setSimpleGlossText(String s)
	{
		txtSimpleGloss.setText(s);
	}
	
	public String getSimplePrefixText()
	{
		return txtSimplePrefix.getText();
	}
	
	public String getSimpleSuffixText()
	{
		return txtSimpleSuffix.getText();
	}
	
	public String getSimpleInfixText()
	{
		return txtSimpleInfix.getText();
	}
	
	public String getSimpleNewWordText()
	{
		return txtSimpleNewWord.getText();
	}
	
	public String getSimpleTranslationText()
	{
		return txtSimpleTranslation.getText();
	}
	
	public String getSimpleGlossText()
	{
		return txtSimpleGloss.getText();
	}
	
	public String getCbxBaseFormText()
	{
		return (String) cbxSimpleBaseForm.getSelectedItem();
	}
	
	public void getCbxBaseFormText(String s)
	{
		cbxSimpleBaseForm.setSelectedItem(s);
	}
	
	public void setCbxModificationText(String s)
	{
		cbxSimpleModification.setSelectedItem(s);
	}
	
	public String getCbxModificationText()
	{
		return (String) cbxSimpleModification.getSelectedItem();
	}
}
